package com.okaixz.manager.article.service.impl;

import com.okaixz.manager.article.domain.CArticle;
import com.okaixz.manager.article.mapper.CArticleMapper;
import com.okaixz.manager.article.service.ICArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * AI写作案例Service业务层处理
 *
 * @author ruoyi
 * @date 2024-08-18
 */
@Service
public class CArticleServiceImpl implements ICArticleService
{
    @Autowired
    private CArticleMapper cArticleMapper;

    /**
     * 查询AI写作案例
     *
     * @param id AI写作案例主键
     * @return AI写作案例
     */
    @Override
    public CArticle selectCArticleById(Long id)
    {
        CArticle cArticle = cArticleMapper.selectCArticleById(id);
        if (cArticle != null) {
            //将浏览量加1
            cArticle.setViews(cArticle.getViews()+1);
            updateCArticle(cArticle);
        }
        return cArticle;
    }

    /**
     * 查询AI写作案例列表
     *
     * @param cArticle AI写作案例
     * @return AI写作案例
     */
    @Override
    public List<CArticle> selectCArticleList(CArticle cArticle)
    {
        return cArticleMapper.selectCArticleList(cArticle);
    }

    /**
     * 新增AI写作案例
     *
     * @param cArticle AI写作案例
     * @return 结果
     */
    @Override
    public int insertCArticle(CArticle cArticle)
    {
        return cArticleMapper.insertCArticle(cArticle);
    }

    /**
     * 修改AI写作案例
     *
     * @param cArticle AI写作案例
     * @return 结果
     */
    @Override
    public int updateCArticle(CArticle cArticle)
    {
        return cArticleMapper.updateCArticle(cArticle);
    }

    /**
     * 批量删除AI写作案例
     *
     * @param ids 需要删除的AI写作案例主键
     * @return 结果
     */
    @Override
    public int deleteCArticleByIds(Long[] ids)
    {
        return cArticleMapper.deleteCArticleByIds(ids);
    }

    /**
     * 删除AI写作案例信息
     *
     * @param id AI写作案例主键
     * @return 结果
     */
    @Override
    public int deleteCArticleById(Long id)
    {
        return cArticleMapper.deleteCArticleById(id);
    }

    @Override
    public List<CArticle> selectHotArticle(CArticle cArticle) {
        return cArticleMapper.selectHotArticleList(cArticle);
    }
}
